/*
 * TrackRegGuiView.java
 */

package trackreggui;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.swing.DropMode;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.tree.TreePath;
import trackreggui.swing.AthletListTransferHandler;
import trackreggui.swing.DisciplinListTransferHandler;
import trackreggui.swing.TreeTransferHandler;
import webreg.model.Athlet;
import webreg.model.Disciplin;
import webreg.model.swing.AthletContainerListModel;
import webreg.model.swing.CompetitionTreeModel;
import webreg.model.swing.DisciplinContainerListModel;
import webreg.model.swing.RegistrationPrintable;

/**
 * The application's main frame.
 */
public class ViewMain extends FrameView {

    public ViewMain(SingleFrameApplication app) {
        super(app);

        mModelController = ModelController.getInstance();
        DataPool.getInstance();

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });

        mAthletDragIcon = resourceMap.getIcon("AthletList.dragIcon");
        athletList.setTransferHandler(new AthletListTransferHandler(mAthletDragIcon));
        disciplinList.setTransferHandler(new DisciplinListTransferHandler(mAthletDragIcon));
        mButtonEnabler = new ViewMainButtonEnabler(this);
        mButtonEnabler.enableButtons(ViewMainButtonEnabler.ButtonEnabling.INITIALIZE);
    }

    @Action
    public void showAboutBox() {
        if (mAboutBox == null) {
            JFrame mainFrame = TrackRegGuiApp.getApplication().getMainFrame();
            mAboutBox = new ViewAbout(mainFrame);
            mAboutBox.setLocationRelativeTo(mainFrame);
        }
        TrackRegGuiApp.getApplication().show(mAboutBox);
    }

    @Action
    public void doNewRegistration() {
        mModelController = null;
        if (mCompetitionBox == null) {
            JFrame mainFrame = TrackRegGuiApp.getApplication().getMainFrame();
            mCompetitionBox = new ViewCompetitionDetails(mainFrame);
            mCompetitionBox.setLocationRelativeTo(mainFrame);
        }
        TrackRegGuiApp.getApplication().show(mCompetitionBox);
        if (((ViewCompetitionDetails) mCompetitionBox).isCanceled() == false) {
            this.competitionTree.setModel( ModelController.getInstance().getCompetitionAsTreeModel() );
            this.competitionTree.setCellRenderer( ModelController.getInstance().getCompetitionTreeCellRender() ) ;
            this.competitionTree.setTransferHandler(new TreeTransferHandler(competitionTree));
            mButtonEnabler.enableButtons(ViewMainButtonEnabler.ButtonEnabling.NEW_REGISTRATION);
        }
    }

    @Action
    public void doOpenRegistration() {
        JFileChooser fileopen = new JFileChooser();
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(trackreggui.TrackRegGuiApp.class).getContext().getResourceMap(ViewMain.class);
        FileNameExtensionFilter filter = new FileNameExtensionFilter( resourceMap.getString("fileFilterExtensionDescription"), resourceMap.getString("fileFilterExtensionName") );
        fileopen.addChoosableFileFilter(filter);
        fileopen.setDialogType(JFileChooser.OPEN_DIALOG);

        int ret = fileopen.showDialog(null, resourceMap.getString("fileOpen.text"));


        if (ret == JFileChooser.APPROVE_OPTION) {
            mModelController.setRegistrationFile( fileopen.getSelectedFile() );
            mModelController.loadRegistration();
            //System.out.println( mModelController.getRegistrationFile().getName() );
            this.competitionTree.setModel( mModelController.getCompetitionAsTreeModel() );
            this.competitionTree.setCellRenderer( mModelController.getCompetitionTreeCellRender() ) ;
            this.competitionTree.setTransferHandler(new TreeTransferHandler(competitionTree));
            mButtonEnabler.enableButtons(ViewMainButtonEnabler.ButtonEnabling.OPEN_REGISTRATION);
        }
    }

    @Action
    public void doSaveRegistration() {
        if (mModelController.getRegistrationFile() == null) {
            doSaveAsRegistration();
        } else {
            mModelController.saveCurrentRegistration();
        }

    }

    @Action
    public void doSaveAsRegistration() {
        JFileChooser filesave = new JFileChooser();
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(trackreggui.TrackRegGuiApp.class).getContext().getResourceMap(ViewMain.class);
        FileNameExtensionFilter filter = new FileNameExtensionFilter( resourceMap.getString("fileFilterExtensionDescription"), resourceMap.getString("fileFilterExtensionName") );
        filesave.addChoosableFileFilter(filter);
        filesave.setDialogType(JFileChooser.SAVE_DIALOG);

        int ret = filesave.showDialog(null, resourceMap.getString("fileSaveAs.text"));

        if (ret == JFileChooser.APPROVE_OPTION) {
            mModelController.setRegistrationFile( filesave.getSelectedFile() );
            System.out.println( mModelController.getRegistrationFile().getName() );
            mModelController.saveCurrentRegistration();
        }
    }
    
    @Action
    public void doPrintRegistration() {
        PrinterJob pjob = PrinterJob.getPrinterJob();
//        pjob.setCopies(1);
//        pjob.setJobName("WebRegGui - Print Registration");
        try {
            if (pjob.printDialog() == true) {
                System.out.println("Print something");
                pjob.setPrintable( new RegistrationPrintable( mModelController.getCompetition(), 1.0, 1.0 ) );
                pjob.print();
                // TODO: implement
            }
        } catch (PrinterException e) {
            //org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(trackreggui.TrackRegGuiApp.class).getContext().getResourceMap(ViewAthletDetails.class);
            JOptionPane.showMessageDialog(null, e.getMessage() ,"Error during printing", JOptionPane.ERROR_MESSAGE);
            Logger.getLogger(ViewAthletDetails.class.getName()).log(Level.SEVERE, null, e);
        }
    }

    @Action
    public void doPrintPreviewRegistration() {
        System.out.println("Print preview");
        PrinterJob pj = PrinterJob.getPrinterJob();
        RegistrationPrintable rp = new RegistrationPrintable( mModelController.getCompetition(), 1.0, 1.0 );

        if (mPrintPreviewBox == null) {
            JFrame mainFrame = TrackRegGuiApp.getApplication().getMainFrame();
            mPrintPreviewBox = new ViewPrintPreview(mainFrame, rp);
            mPrintPreviewBox.setLocationRelativeTo(mainFrame);
        }
        TrackRegGuiApp.getApplication().show(mPrintPreviewBox);
        mPrintPreviewBox.dispose();
        mPrintPreviewBox = null;

     }

    @Action
    public void doCloseRegistration() {
//        mModelController = new ModelController();
        // TODO: detect change and ask for save!
        mButtonEnabler.enableButtons(ViewMainButtonEnabler.ButtonEnabling.CLOSE_REGISTRATION);
        this.competitionTree.setModel( null );
    }

    @Action
    public void addAthletToPool() {
        if (mAthletBox == null) {
            JFrame mainFrame = TrackRegGuiApp.getApplication().getMainFrame();
            mAthletBox = new ViewAthletDetails(mainFrame);
            mAthletBox.setLocationRelativeTo(mainFrame);
        }
        TrackRegGuiApp.getApplication().show(mAthletBox);
        Athlet toAdd = ((ViewAthletDetails)mAthletBox).getAthlet();

        if ( toAdd != null ) {
            int addPosition = athletList.getSelectedIndex();
            if (addPosition < 0 ) addPosition = 0;
            ((AthletContainerListModel)athletList.getModel()).addElementAt(addPosition, toAdd);
        }
        mAthletBox.dispose();
        mAthletBox = null;
    }

    @Action
    public void editAthlet() {
        Athlet toEdit = (Athlet)athletList.getModel().getElementAt(athletList.getSelectedIndex());
        if (mAthletBox == null) {
            JFrame mainFrame = TrackRegGuiApp.getApplication().getMainFrame();
            mAthletBox = new ViewAthletDetails(mainFrame);
            mAthletBox.setLocationRelativeTo(mainFrame);
        }
        ((ViewAthletDetails)mAthletBox).setAthlet(toEdit);
        TrackRegGuiApp.getApplication().show(mAthletBox);
        Athlet toReplace = ((ViewAthletDetails)mAthletBox).getAthlet();

        if ( toReplace != null ) {
            int editPosition = athletList.getSelectedIndex();
            if (editPosition < 0 ) editPosition = 0;
            ((AthletContainerListModel)athletList.getModel()).editElementAt(editPosition, toReplace);
        }
        //mAthletBox.dispose();
        //mAthletBox = null;

    }

    @Action
    public void deleteAthletFromPool() {
        int deletePosition = athletList.getSelectedIndex();
        if (deletePosition < 0) deletePosition = 0;
        Athlet toDeleteAthlet = (Athlet)athletList.getModel().getElementAt(deletePosition);
        int userResponse = JOptionPane.showConfirmDialog(TrackRegGuiApp.getApplication().getMainFrame(),
                "Wollen Sie den Athleten '" + toDeleteAthlet.getSurname() + " " + toDeleteAthlet.getName() +
                " (" + toDeleteAthlet.getYearOfBirthAsString() + ") " +
                "' wirklich löschen?",
                "Alhlet löschen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if ( userResponse == JOptionPane.YES_OPTION ) {
            // really delete the age table
            ((AthletContainerListModel)athletList.getModel()).removeElementAt(deletePosition);
        }

    }


    @Action
    public void addDisciplinToPool() {
       if (mDisciplinBox == null) {
            JFrame mainFrame = TrackRegGuiApp.getApplication().getMainFrame();
            mDisciplinBox = new ViewDisciplinDetails(mainFrame);
            mDisciplinBox.setLocationRelativeTo(mainFrame);
        }
        TrackRegGuiApp.getApplication().show(mDisciplinBox);
        Disciplin toAdd = ((ViewDisciplinDetails)mDisciplinBox).getDisciplin();

        if ( toAdd != null ) {
            int addPosition = disciplinList.getSelectedIndex();
            if (addPosition < 0 ) addPosition = 0;
            ((DisciplinContainerListModel)disciplinList.getModel()).addElementAt(addPosition, toAdd);
        }
        mDisciplinBox.dispose();
        mDisciplinBox = null;
    }

    @Action
    public void editDisciplin() {
        Disciplin toEdit = (Disciplin)disciplinList.getModel().getElementAt(disciplinList.getSelectedIndex());
        System.out.println("Here " + toEdit.getLabel() );
        if (mDisciplinBox == null) {
            JFrame mainFrame = TrackRegGuiApp.getApplication().getMainFrame();
            mDisciplinBox = new ViewDisciplinDetails(mainFrame);
            mDisciplinBox.setLocationRelativeTo(mainFrame);
        }
        ((ViewDisciplinDetails)mDisciplinBox).setDisciplin(toEdit);
        TrackRegGuiApp.getApplication().show(mDisciplinBox);
        Disciplin toReplace = ((ViewDisciplinDetails)mDisciplinBox).getDisciplin();

        if ( toReplace != null ) {
            int editPosition = disciplinList.getSelectedIndex();
            if (editPosition < 0 ) editPosition = 0;
            ((DisciplinContainerListModel)disciplinList.getModel()).editElementAt(editPosition, toReplace);
        }
    }

    @Action
    public void deleteDisciplinFromPool() {
        int deletePosition = disciplinList.getSelectedIndex();
        if (deletePosition < 0) deletePosition = 0;
        Disciplin toDelete = (Disciplin)disciplinList.getModel().getElementAt(deletePosition);
        int userResponse = JOptionPane.showConfirmDialog(TrackRegGuiApp.getApplication().getMainFrame(),
                "Wollen Sie die Disciplin '" + toDelete.getLabel() + "' wirklich löschen?",
                "Disciplin löschen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if ( userResponse == JOptionPane.YES_OPTION ) {
            // really delete the age table
            ((DisciplinContainerListModel)disciplinList.getModel()).removeElementAt(deletePosition);
        }
    }

    @Action
    public void showAgeTableEditor() {
        if (mAgeTableEditor == null) {
            JFrame mainFrame = TrackRegGuiApp.getApplication().getMainFrame();
            mAgeTableEditor = new ViewAgeTableEditor(mainFrame);
            mAgeTableEditor.setLocationRelativeTo(mainFrame);
        }
        TrackRegGuiApp.getApplication().show(mAgeTableEditor);
    }

    @Action
    public void closeActionWindow() {
        DataPool.getInstance().saveAllPoolData();
        Configurator.getInstance().saveAllConfigurationData();
        System.out.println("All settings saved");
        org.jdesktop.application.Application.getInstance(trackreggui.TrackRegGuiApp.class).getContext().getApplication().exit();
    }

    @Action
    public void addAthletToCompetition() {
        System.out.println("Add athlet to registration");
        TreePath thePath = competitionTree.getSelectionPath();
        if (thePath == null) {
            thePath = new TreePath( competitionTree.getModel().getRoot() );
        }
        // create a new copy of the athlet - or adding disciplins will modify the athlet pool
        Athlet newAthlet = (Athlet) ( (Athlet)athletList.getModel().getElementAt( athletList.getSelectedIndex() ) ).clone();
        ((CompetitionTreeModel)competitionTree.getModel()).addElementAt(thePath, newAthlet);
    }

    @Action
    public void addDisciplinToCompetition() {
        System.out.println("Add disciplin to athlet in registration");
        TreePath thePath = competitionTree.getSelectionPath();
        if (thePath == null) {
            thePath = new TreePath( competitionTree.getModel().getRoot() );
        }
        Disciplin newDisciplin = new Disciplin( (Disciplin)disciplinList.getModel().getElementAt( disciplinList.getSelectedIndex() ) );
        ((CompetitionTreeModel)competitionTree.getModel()).addElementAt(thePath, newDisciplin);
    }

    @Action
    public void removeAthletFromCompetition() {
        System.out.println("Remove athlet from registration");
        TreePath thePath = competitionTree.getSelectionPath();
        if (thePath != null) {
            ((CompetitionTreeModel)competitionTree.getModel()).removeElementAt(thePath);
        }
    }

    @Action
    public void removeDisciplinFromCompetition() {
        System.out.println("Remove disciplin from athlet in registration");
        TreePath thePath = competitionTree.getSelectionPath();
        if (thePath != null) {
            ((CompetitionTreeModel)competitionTree.getModel()).removeElementAt(thePath);
        }
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        newMenuItem = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        openMenuItem = new javax.swing.JMenuItem();
        saveMenuItem = new javax.swing.JMenuItem();
        saveAsMenuItem = new javax.swing.JMenuItem();
        printMenuItem = new javax.swing.JMenuItem();
        printPreviewMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        closeMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        settingsMenu = new javax.swing.JMenu();
        ageTableMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        menuToolBar = new javax.swing.JToolBar();
        newButton = new javax.swing.JButton();
        openButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        printButton = new javax.swing.JButton();
        propertiesButton = new javax.swing.JButton();
        helpButton = new javax.swing.JButton();
        mainPanel = new javax.swing.JPanel();
        horizontalSplitPane = new javax.swing.JSplitPane();
        treePanel = new javax.swing.JPanel();
        registrationCaptionLabel = new javax.swing.JLabel();
        treeScrollPane = new javax.swing.JScrollPane();
        competitionTree = new javax.swing.JTree();
        dataPoolsPanel = new javax.swing.JPanel();
        jSplitPane1 = new javax.swing.JSplitPane();
        athletsPanel = new javax.swing.JPanel();
        athletCaptionLabel = new javax.swing.JLabel();
        filterAthletTextField = new javax.swing.JTextField();
        athletScrollPane = new javax.swing.JScrollPane();
        athletList = new javax.swing.JList();
        addAthletButton = new javax.swing.JButton();
        editAthletButton = new javax.swing.JButton();
        removeAthletButton = new javax.swing.JButton();
        addAthletToRegistrationButton = new javax.swing.JButton();
        removeAthletFromRegistrationButton = new javax.swing.JButton();
        disciplinPanel = new javax.swing.JPanel();
        disciplinCaptionLabel = new javax.swing.JLabel();
        filterDisciplinTextField = new javax.swing.JTextField();
        disciplinScrollPane = new javax.swing.JScrollPane();
        disciplinList = new javax.swing.JList();
        addDisciplinButton = new javax.swing.JButton();
        editDisciplinButton = new javax.swing.JButton();
        removeDisciplinButton = new javax.swing.JButton();
        addDisciplinToAthletButton = new javax.swing.JButton();
        removeDisciplinFromAthletButton = new javax.swing.JButton();

        menuBar.setName("menuBar"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(trackreggui.TrackRegGuiApp.class).getContext().getActionMap(ViewMain.class, this);
        fileMenu.setAction(actionMap.get("quit")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(trackreggui.TrackRegGuiApp.class).getContext().getResourceMap(ViewMain.class);
        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        newMenuItem.setAction(actionMap.get("doNewRegistration")); // NOI18N
        newMenuItem.setIcon(resourceMap.getIcon("newMenuItem.icon")); // NOI18N
        newMenuItem.setText(resourceMap.getString("newMenuItem.text")); // NOI18N
        newMenuItem.setName("newMenuItem"); // NOI18N
        fileMenu.add(newMenuItem);

        jSeparator2.setName("jSeparator2"); // NOI18N
        fileMenu.add(jSeparator2);

        openMenuItem.setAction(actionMap.get("doOpenRegistration")); // NOI18N
        openMenuItem.setIcon(resourceMap.getIcon("openMenuItem.icon")); // NOI18N
        openMenuItem.setText(resourceMap.getString("openMenuItem.text")); // NOI18N
        openMenuItem.setName("openMenuItem"); // NOI18N
        fileMenu.add(openMenuItem);

        saveMenuItem.setAction(actionMap.get("doSaveRegistration")); // NOI18N
        saveMenuItem.setIcon(resourceMap.getIcon("saveMenuItem.icon")); // NOI18N
        saveMenuItem.setText(resourceMap.getString("saveMenuItem.text")); // NOI18N
        saveMenuItem.setName("saveMenuItem"); // NOI18N
        fileMenu.add(saveMenuItem);

        saveAsMenuItem.setAction(actionMap.get("doSaveAsRegistration")); // NOI18N
        saveAsMenuItem.setText(resourceMap.getString("saveAsMenuItem.text")); // NOI18N
        saveAsMenuItem.setName("saveAsMenuItem"); // NOI18N
        fileMenu.add(saveAsMenuItem);

        printMenuItem.setAction(actionMap.get("doPrintRegistration")); // NOI18N
        printMenuItem.setIcon(resourceMap.getIcon("printMenuItem.icon")); // NOI18N
        printMenuItem.setText(resourceMap.getString("printMenuItem.text")); // NOI18N
        printMenuItem.setName("printMenuItem"); // NOI18N
        fileMenu.add(printMenuItem);

        printPreviewMenuItem.setAction(actionMap.get("doPrintPreviewRegistration")); // NOI18N
        printPreviewMenuItem.setIcon(resourceMap.getIcon("printPreviewMenuItem.icon")); // NOI18N
        printPreviewMenuItem.setText(resourceMap.getString("printPreviewMenuItem.text")); // NOI18N
        printPreviewMenuItem.setToolTipText(resourceMap.getString("printPreviewMenuItem.toolTipText")); // NOI18N
        printPreviewMenuItem.setName("printPreviewMenuItem"); // NOI18N
        fileMenu.add(printPreviewMenuItem);

        jSeparator1.setName("jSeparator1"); // NOI18N
        fileMenu.add(jSeparator1);

        closeMenuItem.setAction(actionMap.get("doCloseRegistration")); // NOI18N
        closeMenuItem.setText(resourceMap.getString("closeMenuItem.text")); // NOI18N
        closeMenuItem.setName("closeMenuItem"); // NOI18N
        fileMenu.add(closeMenuItem);

        exitMenuItem.setAction(actionMap.get("closeActionWindow")); // NOI18N
        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        settingsMenu.setText(resourceMap.getString("settingsMenu.text")); // NOI18N
        settingsMenu.setName("settingsMenu"); // NOI18N

        ageTableMenuItem.setAction(actionMap.get("showAgeTableEditor")); // NOI18N
        ageTableMenuItem.setIcon(resourceMap.getIcon("ageTableMenuItem.icon")); // NOI18N
        ageTableMenuItem.setText(resourceMap.getString("ageTableMenuItem.text")); // NOI18N
        ageTableMenuItem.setName("ageTableMenuItem"); // NOI18N
        settingsMenu.add(ageTableMenuItem);

        menuBar.add(settingsMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setIcon(resourceMap.getIcon("aboutMenuItem.icon")); // NOI18N
        aboutMenuItem.setText(resourceMap.getString("aboutMenuItem.text")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setMinimumSize(new java.awt.Dimension(0, 27));
        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 386, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        menuToolBar.setRollover(true);
        menuToolBar.setMargin(null);
        menuToolBar.setMaximumSize(new java.awt.Dimension(32767, 32767));
        menuToolBar.setMinimumSize(new java.awt.Dimension(0, 27));
        menuToolBar.setName("menuToolBar"); // NOI18N

        newButton.setAction(actionMap.get("doNewRegistration")); // NOI18N
        newButton.setIcon(resourceMap.getIcon("newButton.icon")); // NOI18N
        newButton.setText(resourceMap.getString("newButton.text")); // NOI18N
        newButton.setFocusable(false);
        newButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        newButton.setName("newButton"); // NOI18N
        newButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        menuToolBar.add(newButton);

        openButton.setAction(actionMap.get("doOpenRegistration")); // NOI18N
        openButton.setIcon(resourceMap.getIcon("openButton.icon")); // NOI18N
        openButton.setText(resourceMap.getString("openButton.text")); // NOI18N
        openButton.setFocusable(false);
        openButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        openButton.setName("openButton"); // NOI18N
        openButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        menuToolBar.add(openButton);

        saveButton.setAction(actionMap.get("doSaveRegistration")); // NOI18N
        saveButton.setIcon(resourceMap.getIcon("saveButton.icon")); // NOI18N
        saveButton.setText(resourceMap.getString("saveButton.text")); // NOI18N
        saveButton.setFocusable(false);
        saveButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        saveButton.setName("saveButton"); // NOI18N
        saveButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        menuToolBar.add(saveButton);

        printButton.setAction(actionMap.get("doPrintRegistration")); // NOI18N
        printButton.setIcon(resourceMap.getIcon("printButton.icon")); // NOI18N
        printButton.setText(resourceMap.getString("printButton.text")); // NOI18N
        printButton.setFocusable(false);
        printButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        printButton.setName("printButton"); // NOI18N
        printButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        menuToolBar.add(printButton);

        propertiesButton.setAction(actionMap.get("showAgeTableEditor")); // NOI18N
        propertiesButton.setIcon(resourceMap.getIcon("propertiesButton.icon")); // NOI18N
        propertiesButton.setText(resourceMap.getString("propertiesButton.text")); // NOI18N
        propertiesButton.setFocusable(false);
        propertiesButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        propertiesButton.setName("propertiesButton"); // NOI18N
        propertiesButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        menuToolBar.add(propertiesButton);

        helpButton.setAction(actionMap.get("showAboutBox")); // NOI18N
        helpButton.setIcon(resourceMap.getIcon("helpButton.icon")); // NOI18N
        helpButton.setText(resourceMap.getString("helpButton.text")); // NOI18N
        helpButton.setFocusable(false);
        helpButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        helpButton.setName("helpButton"); // NOI18N
        helpButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        menuToolBar.add(helpButton);

        mainPanel.setAlignmentX(1.0F);
        mainPanel.setAlignmentY(1.0F);
        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setPreferredSize(new java.awt.Dimension(375, 300));
        mainPanel.setLayout(new java.awt.BorderLayout());

        horizontalSplitPane.setBorder(null);
        horizontalSplitPane.setDividerSize(10);
        horizontalSplitPane.setResizeWeight(0.5);
        horizontalSplitPane.setContinuousLayout(true);
        horizontalSplitPane.setName("horizontalSplitPane"); // NOI18N
        horizontalSplitPane.setOneTouchExpandable(true);

        treePanel.setName("treePanel"); // NOI18N
        treePanel.setLayout(new java.awt.GridBagLayout());

        registrationCaptionLabel.setText(resourceMap.getString("registrationCaptionLabel.text")); // NOI18N
        registrationCaptionLabel.setName("registrationCaptionLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        treePanel.add(registrationCaptionLabel, gridBagConstraints);

        treeScrollPane.setAlignmentX(1.0F);
        treeScrollPane.setAlignmentY(1.0F);
        treeScrollPane.setMaximumSize(new java.awt.Dimension(2147483647, 2147483647));
        treeScrollPane.setMinimumSize(new java.awt.Dimension(200, 300));
        treeScrollPane.setName("treeScrollPane"); // NOI18N
        treeScrollPane.setPreferredSize(new java.awt.Dimension(200, 300));

        competitionTree.setModel(null);
        competitionTree.setToolTipText(resourceMap.getString("competitionTree.toolTipText")); // NOI18N
        competitionTree.setAlignmentX(1.0F);
        competitionTree.setAlignmentY(1.0F);
        competitionTree.setDragEnabled(true);
        competitionTree.setDropMode(DropMode.ON_OR_INSERT);
        competitionTree.setMaximumSize(new java.awt.Dimension(2147483647, 2147483647));
        competitionTree.setMinimumSize(new java.awt.Dimension(200, 300));
        competitionTree.setName("competitionTree"); // NOI18N
        competitionTree.setPreferredSize(new java.awt.Dimension(200, 300));
        competitionTree.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                competitionTreeMouseClicked(evt);
            }
        });
        treeScrollPane.setViewportView(competitionTree);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        treePanel.add(treeScrollPane, gridBagConstraints);

        horizontalSplitPane.setLeftComponent(treePanel);

        dataPoolsPanel.setName("dataPoolsPanel"); // NOI18N
        dataPoolsPanel.setLayout(new java.awt.BorderLayout());

        jSplitPane1.setBorder(null);
        jSplitPane1.setDividerSize(10);
        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane1.setResizeWeight(0.5);
        jSplitPane1.setToolTipText(resourceMap.getString("verticalSplitPane.toolTipText")); // NOI18N
        jSplitPane1.setContinuousLayout(true);
        jSplitPane1.setName("verticalSplitPane"); // NOI18N
        jSplitPane1.setOneTouchExpandable(true);

        athletsPanel.setToolTipText(resourceMap.getString("athletsPanel.toolTipText")); // NOI18N
        athletsPanel.setName("athletsPanel"); // NOI18N
        athletsPanel.setLayout(new java.awt.GridBagLayout());

        athletCaptionLabel.setText(resourceMap.getString("athletCaptionLabel.text")); // NOI18N
        athletCaptionLabel.setToolTipText(resourceMap.getString("athletCaptionLabel.toolTipText")); // NOI18N
        athletCaptionLabel.setName("athletCaptionLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        athletsPanel.add(athletCaptionLabel, gridBagConstraints);

        filterAthletTextField.setText(resourceMap.getString("filterAthletTextField.text")); // NOI18N
        filterAthletTextField.setToolTipText(resourceMap.getString("filterAthletTextField.toolTipText")); // NOI18N
        filterAthletTextField.setAlignmentX(0.0F);
        filterAthletTextField.setAlignmentY(0.0F);
        filterAthletTextField.setMinimumSize(new java.awt.Dimension(150, 23));
        filterAthletTextField.setName("filterAthletTextField"); // NOI18N
        filterAthletTextField.setPreferredSize(new java.awt.Dimension(23, 23));
        filterAthletTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                filterAthletTextFieldKeyReleased(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        athletsPanel.add(filterAthletTextField, gridBagConstraints);

        athletScrollPane.setAlignmentX(1.0F);
        athletScrollPane.setAlignmentY(1.0F);
        athletScrollPane.setName("athletScrollPane"); // NOI18N

        athletList.setModel(DataPool.getInstance().getAthletPoolAsListModel());
        athletList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        athletList.setToolTipText(resourceMap.getString("athletList.toolTipText")); // NOI18N
        athletList.setAlignmentX(1.0F);
        athletList.setAlignmentY(1.0F);
        athletList.setDragEnabled(true);
        athletList.setMaximumSize(new java.awt.Dimension(2147483647, 2147483647));
        athletList.setMinimumSize(new java.awt.Dimension(150, 150));
        athletList.setName("athletList"); // NOI18N
        athletList.setPreferredSize(new java.awt.Dimension(150, 150));
        athletList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                athletListMouseClicked(evt);
            }
        });
        athletScrollPane.setViewportView(athletList);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        athletsPanel.add(athletScrollPane, gridBagConstraints);

        addAthletButton.setAction(actionMap.get("addAthletToPool")); // NOI18N
        addAthletButton.setIcon(resourceMap.getIcon("addAthletButton.icon")); // NOI18N
        addAthletButton.setText(resourceMap.getString("addAthletButton.text")); // NOI18N
        addAthletButton.setToolTipText(resourceMap.getString("addAthletButton.toolTipText")); // NOI18N
        addAthletButton.setAlignmentY(0.0F);
        addAthletButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        addAthletButton.setMaximumSize(new java.awt.Dimension(23, 23));
        addAthletButton.setMinimumSize(new java.awt.Dimension(23, 23));
        addAthletButton.setName("addAthletButton"); // NOI18N
        addAthletButton.setPreferredSize(new java.awt.Dimension(23, 23));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        athletsPanel.add(addAthletButton, gridBagConstraints);

        editAthletButton.setAction(actionMap.get("editAthlet")); // NOI18N
        editAthletButton.setIcon(resourceMap.getIcon("editAthletButton.icon")); // NOI18N
        editAthletButton.setText(resourceMap.getString("editAthletButton.text")); // NOI18N
        editAthletButton.setToolTipText(resourceMap.getString("editAthletButton.toolTipText")); // NOI18N
        editAthletButton.setAlignmentY(0.0F);
        editAthletButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        editAthletButton.setMaximumSize(new java.awt.Dimension(23, 23));
        editAthletButton.setMinimumSize(new java.awt.Dimension(23, 23));
        editAthletButton.setName("editAthletButton"); // NOI18N
        editAthletButton.setPreferredSize(new java.awt.Dimension(23, 23));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        athletsPanel.add(editAthletButton, gridBagConstraints);

        removeAthletButton.setAction(actionMap.get("deleteAthletFromPool")); // NOI18N
        removeAthletButton.setIcon(resourceMap.getIcon("removeAthletButton.icon")); // NOI18N
        removeAthletButton.setText(resourceMap.getString("removeAthletButton.text")); // NOI18N
        removeAthletButton.setToolTipText(resourceMap.getString("removeAthletButton.toolTipText")); // NOI18N
        removeAthletButton.setAlignmentY(0.0F);
        removeAthletButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        removeAthletButton.setMaximumSize(new java.awt.Dimension(23, 23));
        removeAthletButton.setMinimumSize(new java.awt.Dimension(23, 23));
        removeAthletButton.setName("removeAthletButton"); // NOI18N
        removeAthletButton.setPreferredSize(new java.awt.Dimension(23, 23));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        athletsPanel.add(removeAthletButton, gridBagConstraints);

        addAthletToRegistrationButton.setAction(actionMap.get("addAthletToCompetition")); // NOI18N
        addAthletToRegistrationButton.setIcon(resourceMap.getIcon("addAthletToRegistration.icon")); // NOI18N
        addAthletToRegistrationButton.setText(resourceMap.getString("addAthletToRegistration.text")); // NOI18N
        addAthletToRegistrationButton.setToolTipText(resourceMap.getString("addAthletToRegistration.toolTipText")); // NOI18N
        addAthletToRegistrationButton.setAlignmentY(0.0F);
        addAthletToRegistrationButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        addAthletToRegistrationButton.setMaximumSize(new java.awt.Dimension(23, 23));
        addAthletToRegistrationButton.setMinimumSize(new java.awt.Dimension(23, 23));
        addAthletToRegistrationButton.setName("addAthletToRegistration"); // NOI18N
        addAthletToRegistrationButton.setPreferredSize(new java.awt.Dimension(23, 23));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        athletsPanel.add(addAthletToRegistrationButton, gridBagConstraints);

        removeAthletFromRegistrationButton.setAction(actionMap.get("removeAthletFromCompetition")); // NOI18N
        removeAthletFromRegistrationButton.setIcon(resourceMap.getIcon("removeAthletFromRegistrationButton.icon")); // NOI18N
        removeAthletFromRegistrationButton.setText(resourceMap.getString("removeAthletFromRegistrationButton.text")); // NOI18N
        removeAthletFromRegistrationButton.setToolTipText(resourceMap.getString("removeAthletFromRegistrationButton.toolTipText")); // NOI18N
        removeAthletFromRegistrationButton.setAlignmentY(0.0F);
        removeAthletFromRegistrationButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        removeAthletFromRegistrationButton.setMaximumSize(new java.awt.Dimension(23, 23));
        removeAthletFromRegistrationButton.setMinimumSize(new java.awt.Dimension(23, 23));
        removeAthletFromRegistrationButton.setName("removeAthletFromRegistrationButton"); // NOI18N
        removeAthletFromRegistrationButton.setPreferredSize(new java.awt.Dimension(23, 23));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        athletsPanel.add(removeAthletFromRegistrationButton, gridBagConstraints);

        jSplitPane1.setLeftComponent(athletsPanel);

        disciplinPanel.setToolTipText(resourceMap.getString("disciplinPanel.toolTipText")); // NOI18N
        disciplinPanel.setName("disciplinPanel"); // NOI18N
        disciplinPanel.setLayout(new java.awt.GridBagLayout());

        disciplinCaptionLabel.setText(resourceMap.getString("disciplinCaptionLabel.text")); // NOI18N
        disciplinCaptionLabel.setToolTipText(resourceMap.getString("disciplinCaptionLabel.toolTipText")); // NOI18N
        disciplinCaptionLabel.setName("disciplinCaptionLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 5);
        disciplinPanel.add(disciplinCaptionLabel, gridBagConstraints);

        filterDisciplinTextField.setText(resourceMap.getString("filterDisciplinTextField.text")); // NOI18N
        filterDisciplinTextField.setToolTipText(resourceMap.getString("filterDisciplinTextField.toolTipText")); // NOI18N
        filterDisciplinTextField.setAlignmentX(0.0F);
        filterDisciplinTextField.setAlignmentY(0.0F);
        filterDisciplinTextField.setName("filterDisciplinTextField"); // NOI18N
        filterDisciplinTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                filterDisciplinTextFieldKeyReleased(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        disciplinPanel.add(filterDisciplinTextField, gridBagConstraints);

        disciplinScrollPane.setName("disciplinScrollPane"); // NOI18N

        disciplinList.setModel(DataPool.getInstance().getDisciplinPoolAsListModel());
        disciplinList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        disciplinList.setToolTipText(resourceMap.getString("disciplinList.toolTipText")); // NOI18N
        disciplinList.setAlignmentX(0.0F);
        disciplinList.setAlignmentY(0.0F);
        disciplinList.setDragEnabled(true);
        disciplinList.setDropMode(DropMode.ON_OR_INSERT);
        disciplinList.setMaximumSize(new java.awt.Dimension(2147483647, 2147483647));
        disciplinList.setName("disciplinList"); // NOI18N
        disciplinList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                disciplinListMouseClicked(evt);
            }
        });
        disciplinScrollPane.setViewportView(disciplinList);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        disciplinPanel.add(disciplinScrollPane, gridBagConstraints);

        addDisciplinButton.setAction(actionMap.get("addDisciplinToPool")); // NOI18N
        addDisciplinButton.setIcon(resourceMap.getIcon("addDisciplinButton.icon")); // NOI18N
        addDisciplinButton.setText(resourceMap.getString("addDisciplinButton.text")); // NOI18N
        addDisciplinButton.setToolTipText(resourceMap.getString("addDisciplinButton.toolTipText")); // NOI18N
        addDisciplinButton.setAlignmentY(0.0F);
        addDisciplinButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        addDisciplinButton.setMaximumSize(new java.awt.Dimension(23, 23));
        addDisciplinButton.setMinimumSize(new java.awt.Dimension(23, 23));
        addDisciplinButton.setName("addDisciplinButton"); // NOI18N
        addDisciplinButton.setPreferredSize(new java.awt.Dimension(23, 23));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        disciplinPanel.add(addDisciplinButton, gridBagConstraints);

        editDisciplinButton.setAction(actionMap.get("editDisciplin")); // NOI18N
        editDisciplinButton.setIcon(resourceMap.getIcon("editDisciplinButton.icon")); // NOI18N
        editDisciplinButton.setText(resourceMap.getString("editDisciplinButton.text")); // NOI18N
        editDisciplinButton.setToolTipText(resourceMap.getString("editDisciplinButton.toolTipText")); // NOI18N
        editDisciplinButton.setAlignmentY(0.0F);
        editDisciplinButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        editDisciplinButton.setMaximumSize(new java.awt.Dimension(23, 23));
        editDisciplinButton.setMinimumSize(new java.awt.Dimension(23, 23));
        editDisciplinButton.setName("editDisciplinButton"); // NOI18N
        editDisciplinButton.setPreferredSize(new java.awt.Dimension(23, 23));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        disciplinPanel.add(editDisciplinButton, gridBagConstraints);

        removeDisciplinButton.setAction(actionMap.get("deleteDisciplinFromPool")); // NOI18N
        removeDisciplinButton.setIcon(resourceMap.getIcon("removeDisciplinButton.icon")); // NOI18N
        removeDisciplinButton.setText(resourceMap.getString("removeDisciplinButton.text")); // NOI18N
        removeDisciplinButton.setToolTipText(resourceMap.getString("removeDisciplinButton.toolTipText")); // NOI18N
        removeDisciplinButton.setAlignmentY(0.0F);
        removeDisciplinButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        removeDisciplinButton.setMaximumSize(new java.awt.Dimension(23, 23));
        removeDisciplinButton.setMinimumSize(new java.awt.Dimension(23, 23));
        removeDisciplinButton.setName("removeDisciplinButton"); // NOI18N
        removeDisciplinButton.setPreferredSize(new java.awt.Dimension(23, 23));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        disciplinPanel.add(removeDisciplinButton, gridBagConstraints);

        addDisciplinToAthletButton.setAction(actionMap.get("addDisciplinToCompetition")); // NOI18N
        addDisciplinToAthletButton.setIcon(resourceMap.getIcon("addDisciplinToAthletButton.icon")); // NOI18N
        addDisciplinToAthletButton.setText(resourceMap.getString("addDisciplinToAthletButton.text")); // NOI18N
        addDisciplinToAthletButton.setToolTipText(resourceMap.getString("addDisciplinToAthletButton.toolTipText")); // NOI18N
        addDisciplinToAthletButton.setAlignmentY(0.0F);
        addDisciplinToAthletButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        addDisciplinToAthletButton.setMaximumSize(new java.awt.Dimension(23, 23));
        addDisciplinToAthletButton.setMinimumSize(new java.awt.Dimension(23, 23));
        addDisciplinToAthletButton.setName("addDisciplinToAthletButton"); // NOI18N
        addDisciplinToAthletButton.setPreferredSize(new java.awt.Dimension(23, 23));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        disciplinPanel.add(addDisciplinToAthletButton, gridBagConstraints);

        removeDisciplinFromAthletButton.setAction(actionMap.get("removeDisciplinFromCompetition")); // NOI18N
        removeDisciplinFromAthletButton.setIcon(resourceMap.getIcon("removeDisciplinFromAthletButton.icon")); // NOI18N
        removeDisciplinFromAthletButton.setText(resourceMap.getString("removeDisciplinFromAthletButton.text")); // NOI18N
        removeDisciplinFromAthletButton.setToolTipText(resourceMap.getString("removeDisciplinFromAthletButton.toolTipText")); // NOI18N
        removeDisciplinFromAthletButton.setAlignmentY(0.0F);
        removeDisciplinFromAthletButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        removeDisciplinFromAthletButton.setMaximumSize(new java.awt.Dimension(23, 23));
        removeDisciplinFromAthletButton.setMinimumSize(new java.awt.Dimension(23, 23));
        removeDisciplinFromAthletButton.setName("removeDisciplinFromAthletButton"); // NOI18N
        removeDisciplinFromAthletButton.setPreferredSize(new java.awt.Dimension(23, 23));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
        disciplinPanel.add(removeDisciplinFromAthletButton, gridBagConstraints);

        jSplitPane1.setRightComponent(disciplinPanel);

        dataPoolsPanel.add(jSplitPane1, java.awt.BorderLayout.CENTER);

        horizontalSplitPane.setRightComponent(dataPoolsPanel);

        mainPanel.add(horizontalSplitPane, java.awt.BorderLayout.CENTER);

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
        setToolBar(menuToolBar);
    }// </editor-fold>//GEN-END:initComponents

    private void athletListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_athletListMouseClicked
        mButtonEnabler.enableButtons(ViewMainButtonEnabler.ButtonEnabling.SELECT_ATHLETPOOL );
    }//GEN-LAST:event_athletListMouseClicked

    private void disciplinListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_disciplinListMouseClicked
        mButtonEnabler.enableButtons(ViewMainButtonEnabler.ButtonEnabling.SELECT_DISCIPLINPOOL );
    }//GEN-LAST:event_disciplinListMouseClicked

    private void filterAthletTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_filterAthletTextFieldKeyReleased
        System.out.println("Filtere Athleten: " + filterAthletTextField.getText() );
        ((AthletContainerListModel)athletList.getModel()).applyFilter( filterAthletTextField.getText()  );
    }//GEN-LAST:event_filterAthletTextFieldKeyReleased

    private void filterDisciplinTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_filterDisciplinTextFieldKeyReleased
        System.out.println("Filtere Disziplinen: " + filterDisciplinTextField.getText() );
        ((DisciplinContainerListModel)disciplinList.getModel()).applyFilter( filterDisciplinTextField.getText()  );
    }//GEN-LAST:event_filterDisciplinTextFieldKeyReleased

    private void competitionTreeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_competitionTreeMouseClicked
        TreePath thePath = this.competitionTree.getSelectionPath();
        if (thePath == null) {
            thePath = new TreePath( competitionTree.getModel().getRoot() );
        }

        if(evt.getClickCount() == 1) {
            System.out.println("Mouse clicked single.");
        }
        else if(evt.getClickCount() == 2) {
            System.out.println("Mouse clicked double. " + thePath.toString() + "  " + thePath.getLastPathComponent().getClass().getName()  );
            // double clicked on athlet
            if ( thePath.getLastPathComponent() instanceof Athlet) {
                Athlet theAthlet = (Athlet) thePath.getLastPathComponent();
                System.out.println("Athlet double clicked: " + theAthlet.getName() );

                if (mAthletBox == null) {
                    JFrame mainFrame = TrackRegGuiApp.getApplication().getMainFrame();
                    mAthletBox = new ViewAthletDetails(mainFrame);
                    mAthletBox.setLocationRelativeTo(mainFrame);
                }
                ((ViewAthletDetails)mAthletBox).setAthlet(theAthlet);
                TrackRegGuiApp.getApplication().show(mAthletBox);
                Athlet toReplace = ((ViewAthletDetails)mAthletBox).getAthlet();

                if ( toReplace != null ) {
                    System.out.println("Add replaced athlet");
                    toReplace.setDisciplins( theAthlet.getDisciplins() );
                    ((CompetitionTreeModel)competitionTree.getModel()).addElementAt(thePath, toReplace);
                    System.out.println("Remove selection path athlet");
                    ((CompetitionTreeModel)competitionTree.getModel()).removeElementAt(thePath);
                }

            }
            // double clicked on disciplin
            if ( thePath.getLastPathComponent() instanceof Disciplin) {
                Disciplin theDisciplin = (Disciplin) thePath.getLastPathComponent();
                System.out.println("Disciplin double clicked: " + theDisciplin.getLabel() );

                if (mDisciplinBox == null) {
                    JFrame mainFrame = TrackRegGuiApp.getApplication().getMainFrame();
                    mDisciplinBox = new ViewDisciplinDetails(mainFrame);
                    mAthletBox.setLocationRelativeTo(mainFrame);
                }
                ((ViewDisciplinDetails)mDisciplinBox).setDisciplin(theDisciplin);
                TrackRegGuiApp.getApplication().show(mDisciplinBox);
                Disciplin toReplace = ((ViewDisciplinDetails)mDisciplinBox).getDisciplin();

                if ( toReplace != null ) {
                    System.out.println("Add replaced disciplin to athlet in registration");
                    ((CompetitionTreeModel)competitionTree.getModel()).addElementAt(thePath, toReplace);
                    System.out.println("Remove selection path disciplin");
                    ((CompetitionTreeModel)competitionTree.getModel()).removeElementAt(thePath);
                }

            }


        }
    }//GEN-LAST:event_competitionTreeMouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton addAthletButton;
    public javax.swing.JButton addAthletToRegistrationButton;
    public javax.swing.JButton addDisciplinButton;
    public javax.swing.JButton addDisciplinToAthletButton;
    public javax.swing.JMenuItem ageTableMenuItem;
    public javax.swing.JLabel athletCaptionLabel;
    public javax.swing.JList athletList;
    public javax.swing.JScrollPane athletScrollPane;
    public javax.swing.JPanel athletsPanel;
    public javax.swing.JMenuItem closeMenuItem;
    public javax.swing.JTree competitionTree;
    public javax.swing.JPanel dataPoolsPanel;
    public javax.swing.JLabel disciplinCaptionLabel;
    public javax.swing.JList disciplinList;
    public javax.swing.JPanel disciplinPanel;
    public javax.swing.JScrollPane disciplinScrollPane;
    public javax.swing.JButton editAthletButton;
    public javax.swing.JButton editDisciplinButton;
    public javax.swing.JTextField filterAthletTextField;
    public javax.swing.JTextField filterDisciplinTextField;
    public javax.swing.JButton helpButton;
    public javax.swing.JSplitPane horizontalSplitPane;
    public javax.swing.JSeparator jSeparator1;
    public javax.swing.JSeparator jSeparator2;
    public javax.swing.JSplitPane jSplitPane1;
    public javax.swing.JPanel mainPanel;
    public javax.swing.JMenuBar menuBar;
    public javax.swing.JToolBar menuToolBar;
    public javax.swing.JButton newButton;
    public javax.swing.JMenuItem newMenuItem;
    public javax.swing.JButton openButton;
    public javax.swing.JMenuItem openMenuItem;
    public javax.swing.JButton printButton;
    public javax.swing.JMenuItem printMenuItem;
    public javax.swing.JMenuItem printPreviewMenuItem;
    public javax.swing.JProgressBar progressBar;
    public javax.swing.JButton propertiesButton;
    public javax.swing.JLabel registrationCaptionLabel;
    public javax.swing.JButton removeAthletButton;
    public javax.swing.JButton removeAthletFromRegistrationButton;
    public javax.swing.JButton removeDisciplinButton;
    public javax.swing.JButton removeDisciplinFromAthletButton;
    public javax.swing.JMenuItem saveAsMenuItem;
    public javax.swing.JButton saveButton;
    public javax.swing.JMenuItem saveMenuItem;
    public javax.swing.JMenu settingsMenu;
    public javax.swing.JLabel statusAnimationLabel;
    public javax.swing.JLabel statusMessageLabel;
    public javax.swing.JPanel statusPanel;
    public javax.swing.JPanel treePanel;
    public javax.swing.JScrollPane treeScrollPane;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog mAboutBox;
    private ModelController mModelController;
    private Icon mAthletDragIcon;
    private JDialog mCompetitionBox;
    private JDialog mAthletBox;
    private JDialog mDisciplinBox;
    private JDialog mAgeTableEditor;
    private JDialog mPrintPreviewBox;

    private ViewMainButtonEnabler mButtonEnabler;
    
}
